package com.lh.runmanage.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lh.runmanage.model.ProductModel;
import com.lh.runmanage.model.ResultVOPage;
import com.lh.runmanage.service.ProductService;
import com.lh.runmanage.unit.GetPropertiesClass;
import com.lh.runmanage.unit.ResultStruct;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：梁昊，后端工程师：梁昊
 * @create 2021-07-24 14:53
 * @function
 * @editLog
 */
@RestController
@RequestMapping("/productController")
@Api(value = "产品信息控制层", description = "系统运行态势平台展示端")
public class ProductController {
    @Autowired
    ProductService productService;
    @Autowired
    GetPropertiesClass getPropertiesClass;

    /**
     * 展示端方法：P2，方法ID：SE20210724145056563572B22D76A36
     *
     * @param page 当前页数
     * @param limit 每页条数
     * @return 产品列表
     */
    @ApiOperation(value = "展示端方法：P2[产品列表],方法ID：SE20210724145056563572B22D76A36", notes = "/productController/V1/selectProduct?page=page&limit=limit")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页数", dataType = "String")
            , @ApiImplicitParam(name = "limit", value = "每页条数", dataType = "String")
    })
    @PostMapping("/V1/selectProduct")
    public ResultVOPage selectProduct(
             @RequestParam(value = "page", defaultValue = "1") int page,
             @RequestParam(value = "limit", defaultValue = "10") int limit) {
        PageHelper.startPage(page, limit);
        List<ProductModel> productModels = productService.selectProduct();
        PageInfo pageInfo = new PageInfo<>(productModels, limit);
        return ResultStruct.successPage(productModels, pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal());
    }
}
